﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.WaterReadingKardexMeassure.Modify;

namespace University.Workshop.Presentation.WaterReading
{
    /// <summary>
    /// Interaction logic for ModifyKardexMeasure.xaml
    /// </summary>
    public partial class ModifyKardexMeasure : Page, IModifyKardexMeasure
    {
        PresenterModifyKardexMeasure pModifyKardexMeasure;
        public ModifyKardexMeasure(Model.Kardex kardex)
        {
            InitializeComponent();
            pModifyKardexMeasure = new PresenterModifyKardexMeasure(this, kardex);
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            pModifyKardexMeasure.UpdateViewData();
            App.Current.MainWindow.Title = "Cambiar Medidor";
        }

        public void ReturnSearchKardexMeasure()
        {
            this.NavigationService.Navigate(new SearchKardexMeasure());
        }

        #region Fields
        public string Allotment
        {
            set
            {
                AllotmentTxt.Text = value;
            }
        }

        public string Square
        {
            set
            {
                SquareTxt.Text = value;
            }
        }

        public string Name
        {
            set
            {
                NameTxt.Text = value;
            }
        }

        public string LastName
        {
            set
            {
                LastNameTxt.Text = value;
            }
        }

        public string WaterMeasure
        {
            set
            {
                MeasureNumberTxt.Text = value;
            }

            get
            {
                return MeasureNumberTxt.Text;
            }

        }

        public double CurrentRead
        {
            set
            {
                if (value == 0)
                    CurrentReadTxt.Text = string.Empty;
                else
                    CurrentReadTxt.Text = value.ToString();
            }

            get
            {
                if (CurrentReadTxt.Text != string.Empty)
                    return (Convert.ToDouble(CurrentReadTxt.Text));
                else
                    return 0;
            }
        }

        #endregion

        #region Buttons
        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new SearchKardexMeasure());
        }

        private void ChangeBtn_Click(object sender, RoutedEventArgs e)
        {
            pModifyKardexMeasure.ChangeMeasure();
        }
        #endregion

        #region validations
        private void CurrentReadTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !(char.IsDigit(ch) || ch.Equals('.'));
            }
        }

        private void MeasureNumberTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !( ch.Equals('.') || char.IsLetterOrDigit(ch));
            }
        }
        #endregion

        #region Messages
        public void NotifyErrorMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Error!!!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }

        public void NotifySystemMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Atencion!!!", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }
        #endregion

        
    }
}
